﻿using NewRetail.Application.Components.Platform.Entity;
using NewRetail.Application.Core;
using System.Threading.Tasks;

namespace NewRetail.Api.Controllers
{
    [NewRetailRoute("pos-member-type")]
    public class PosMemberTypeController : BaseController<PosMemberType>
    {
        public PosMemberTypeController()
        {
            //
        }

        protected override async Task<PosMemberType> BeforeInsertDataInitial(PosMemberType data)
        {
            if (string.IsNullOrWhiteSpace(data.No))
            {
                data.No = await this.NoGeneratorService.GenerateGeneralNoAsync("MT");
            }
            return await base.BeforeInsertDataInitial(data);
        }

        protected override Task<PosMemberType> BeforeUpdate(PosMemberType entity, PosMemberType data)
        {
            /*
             http://101.34.33.45:90/api/new-retail/pos-member-type/save

{"No":"MT-20210928-00000074","memberTypeName":"类型二","discount":1,"isIntegral":1,"isStoredValue":1,"integralDiscount":1,"Id":"68f560d379e6fdf9d9f239ff3f3e85cd","addTime":"2021-09-28 15:41:45"}



保存时有些字段没保存成功
             */

            entity.memberTypeName = data.memberTypeName;
            entity.discount = data.discount;
            entity.isIntegral = data.isIntegral;
            entity.isStoredValue = data.isStoredValue;
            entity.integralDiscount = data.integralDiscount;

            return base.BeforeUpdate(entity, data);
        }
    }
}
